
import { routerRedux } from 'dva/router';
import api from '../api';

import { varzuhegroup,varjizhungroup } from '../utils/dataConfig'
export default {
	namespace: 'varanalysis',
	state:{},
	subscriptions:{
		setup({dispatch,history}) {
			history.listen(({pathname,query}) => {
				if( pathname === '/specialrisk/varanalysis' ){
					dispatch({
						type: 'getVarList',
					})
				}
			})
		}
	},
	effects:{
		* getVarList({ payload }, { call, put }) {
			const response = yield call(api.getVarAnalysis, payload);
			yield put({
				type: 'getListSuccess',
				payload: response ,
			});
		},
		
	},
	reducers:{
		getListSuccess(state, {payload}) {
			const {data} = payload
			const tableDate = data;
			const overData = tableDate.overallData;
			const lineData = tableDate.lineData;
			// console.log('data>>>>>',tableDate,'=====',overData)
			const vartableDate = [];
			const time1z = {};
			const time1j = {};
			const time3z = {};
			const time3j = {};
			const time6z = {};
			const time6j = {};
			const time12z = {};
			const time12j = {};
			time1z.time = tableDate.formDate[0].time;
			time1z.confidenceLevel = tableDate.formDate[0].varDate[0].confidenceLevel;
			time1z.period = tableDate.formDate[0].period;
			time1z.object = tableDate.formDate[0].object;
			time1z.id = tableDate.formDate[0].varDate[0].indunum;
			time1z.varRate_1 = tableDate.formDate[0].varDate[0].varRate;
			time1z.varValue_1 = tableDate.formDate[0].varDate[0].varValue;
			time1z.esRate_1 = tableDate.formDate[0].varDate[0].esRate;
			time1z.esValue_1 = tableDate.formDate[0].varDate[0].esValue;
			time1z.varRate_2 = tableDate.formDate[0].varDate[1].varRate;
			time1z.varValue_2 = tableDate.formDate[0].varDate[1].varValue;
			time1z.esRate_2 = tableDate.formDate[0].varDate[1].esRate;
			time1z.esValue_2 = tableDate.formDate[0].varDate[1].esValue;
			time1j.time = tableDate.formDate[0].time;
			time1j.object = tableDate.formDate[1].object;
			time1j.confidenceLevel = tableDate.formDate[0].varDate[1].confidenceLevel;
			time1j.varRate_1 = tableDate.formDate[1].varDate[0].varRate;
			time1j.id = tableDate.formDate[1].varDate[0].indunum;
			time1j.varValue_1 = tableDate.formDate[1].varDate[0].varValue;
			time1j.esRate_1 = tableDate.formDate[1].varDate[0].esRate;
			time1j.esValue_1 = tableDate.formDate[1].varDate[0].esValue;
			time1j.varRate_2 = tableDate.formDate[1].varDate[1].varRate;
			time1j.varValue_2 = tableDate.formDate[1].varDate[1].varValue;
			time1j.esRate_2 = tableDate.formDate[1].varDate[1].esRate;
			time1j.esValue_2 = tableDate.formDate[1].varDate[1].esValue;

			time3z.time = tableDate.formDate[2].time;
			time3z.period = tableDate.formDate[2].period;
			time3z.object = tableDate.formDate[2].object;
			time3z.id = tableDate.formDate[2].varDate[0].indunum;
			time3z.varRate_1 = tableDate.formDate[2].varDate[0].varRate;
			time3z.varValue_1 = tableDate.formDate[2].varDate[0].varValue;
			time3z.esRate_1 = tableDate.formDate[2].varDate[0].esRate;
			time3z.esValue_1 = tableDate.formDate[2].varDate[0].esValue;
			time3z.varRate_2 = tableDate.formDate[2].varDate[1].varRate;
			time3z.varValue_2 = tableDate.formDate[2].varDate[1].varValue;
			time3z.esRate_2 = tableDate.formDate[2].varDate[1].esRate;
			time3z.esValue_2 = tableDate.formDate[2].varDate[1].esValue;
			time3j.time = tableDate.formDate[2].time;
			time3j.object = tableDate.formDate[3].object;
			time3j.id = tableDate.formDate[3].varDate[0].indunum;
			time3j.varRate_1 = tableDate.formDate[3].varDate[0].varRate;
			time3j.varValue_1 = tableDate.formDate[3].varDate[0].varValue;
			time3j.esRate_1 = tableDate.formDate[3].varDate[0].esRate;
			time3j.esValue_1 = tableDate.formDate[3].varDate[0].esValue;
			time3j.varRate_2 = tableDate.formDate[3].varDate[1].varRate;
			time3j.varValue_2 = tableDate.formDate[3].varDate[1].varValue;
			time3j.esRate_2 = tableDate.formDate[3].varDate[1].esRate;
			time3j.esValue_2 = tableDate.formDate[3].varDate[1].esValue;

			time6z.time = tableDate.formDate[4].time;
			time6z.period = tableDate.formDate[4].period;
			time6z.object = tableDate.formDate[4].object;
			time6z.id = tableDate.formDate[4].varDate[0].indunum;
			time6z.varRate_1 = tableDate.formDate[4].varDate[0].varRate;
			time6z.varValue_1 = tableDate.formDate[4].varDate[0].varValue;
			time6z.esRate_1 = tableDate.formDate[4].varDate[0].esRate;
			time6z.esValue_1 = tableDate.formDate[4].varDate[0].esValue;
			time6z.varRate_2 = tableDate.formDate[4].varDate[1].varRate;
			time6z.varValue_2 = tableDate.formDate[4].varDate[1].varValue;
			time6z.esRate_2 = tableDate.formDate[4].varDate[1].esRate;
			time6z.esValue_2 = tableDate.formDate[4].varDate[1].esValue;
			time6j.time = tableDate.formDate[4].time;
			time6j.object = tableDate.formDate[5].object;
			time6j.id = tableDate.formDate[5].varDate[0].indunum;
			time6j.varRate_1 = tableDate.formDate[5].varDate[0].varRate;
			time6j.varValue_1 = tableDate.formDate[5].varDate[0].varValue;
			time6j.esRate_1 = tableDate.formDate[5].varDate[0].esRate;
			time6j.esValue_1 = tableDate.formDate[5].varDate[0].esValue;
			time6j.varRate_2 = tableDate.formDate[5].varDate[1].varRate;
			time6j.varValue_2 = tableDate.formDate[5].varDate[1].varValue;
			time6j.esRate_2 = tableDate.formDate[5].varDate[1].esRate;
			time6j.esValue_2 = tableDate.formDate[5].varDate[1].esValue;

			time12z.time = tableDate.formDate[6].time;
			time12z.period = tableDate.formDate[6].period;
			time12z.object = tableDate.formDate[6].object;
			time12z.id = tableDate.formDate[6].varDate[0].indunum;
			time12z.varRate_1 = tableDate.formDate[6].varDate[0].varRate;
			time12z.varValue_1 = tableDate.formDate[6].varDate[0].varValue;
			time12z.esRate_1 = tableDate.formDate[6].varDate[0].esRate;
			time12z.esValue_1 = tableDate.formDate[6].varDate[0].esValue;
			time12z.varRate_2 = tableDate.formDate[6].varDate[1].varRate;
			time12z.varValue_2 = tableDate.formDate[6].varDate[1].varValue;
			time12z.esRate_2 = tableDate.formDate[6].varDate[1].esRate;
			time12z.esValue_2 = tableDate.formDate[6].varDate[1].esValue;
			time12j.time = tableDate.formDate[6].time;
			time12j.object = tableDate.formDate[7].object;
			time12j.id = tableDate.formDate[7].varDate[0].indunum;
			time12j.varRate_1 = tableDate.formDate[7].varDate[0].varRate;
			time12j.varValue_1 = tableDate.formDate[7].varDate[0].varValue;
			time12j.esRate_1 = tableDate.formDate[7].varDate[0].esRate;
			time12j.esValue_1 = tableDate.formDate[7].varDate[0].esValue;
			time12j.varRate_2 = tableDate.formDate[7].varDate[1].varRate;
			time12j.varValue_2 = tableDate.formDate[7].varDate[1].varValue;
			time12j.esRate_2 = tableDate.formDate[7].varDate[1].esRate;
			time12j.esValue_2 = tableDate.formDate[7].varDate[1].esValue;

			vartableDate.push(time1z,time1j,time3z,time3j,time6z,time6j,time12z,time12j)
			// console.log('vartableDate',vartableDate)
			const status=data ? true:false
			return {
				...state,
				status,
				vartable:vartableDate,
				overallData:overData,
				lineData:lineData,
				varzuhelist:varzuhegroup,
				defaultvarzuhe:varzuhegroup[0].name,
				varjizhunlist:varjizhungroup,
				defaultvarjizhun:varjizhungroup[0].name,
			}
		},
	}
}